import { Component, Input, SimpleChanges, OnInit } from '@angular/core';

import { AlertController } from '@ionic/angular';

import { HttpService } from 'src/app/shared/service/http.service';

import { AppGlobalService } from '../../shared/service/app-global.service';
import { EventService } from '../../shared/service/event.service';
@Component({
    selector: 'app-link-list',
    templateUrl: './link-list.component.html',
    styleUrls: ['./link-list.component.scss']
})
export class LinkListComponent implements OnInit {

    @Input() tagData;

    mobile: string;

    constructor(
        private appGlobalService: AppGlobalService,
        private eventService: EventService,
        private alertController: AlertController,
        private http: HttpService
    ) {
    }
    onClick(phone) {
        this.http.changeCallNumber(phone);
      }
    // tslint:disable-next-line:use-life-cycle-interface
    ngOnChanges(changes: SimpleChanges) {
        console.log('message-----> ngOnChanges ...' + JSON.stringify(this.tagData.data));
    }
    ngOnInit() {
        /*this.tagData = {
            'data': [
                {
                    'iconUrl': '../../../assets/img/telephone2.png',
                    'name': '客服热线',
                    'str': '1234567890'
                }, {
                    'iconUrl': '../../../assets/img/telephone2.png',
                    'name': '客服热线',
                    'str': '1234567890'
                }, {
                    'iconUrl': '../../../assets/img/telephone2.png',
                    'name': '客服热线',
                    'str': '1234567890'
                }
            ]
        };*/
        this.eventService.eventEmit.on('refreshMyPage', () => {
            const tempTagDate = JSON.parse(localStorage.getItem('tag.IconListLogic'));
            this.tagData = tempTagDate;
            this.mobile = this.tagData.data.presale_phone;
            // localStorage.removeItem('tag.IconListLogic');
        });
        this.mobile = this.tagData.data.presale_phone;

    }

    jumpToPage(obj) {
        const sessionId = localStorage.getItem('sessionId');
        const pageParams = {
            pageId: obj.target,
            params: {},
            sessionId: sessionId
        };
        this.appGlobalService.goToForward(pageParams);
    }

}
